import { Component } from '@angular/core';
import { NavController, ModalController, NavParams } from 'ionic-angular';
import { NoticeService } from '../../../providers/notice-service';
import { UrlService } from '../../../providers/url-service';
import { Api } from '../../../providers/api-service';
import { PageRewardPage } from '../../page-reward/page-reward';
/**
 * 个人详情
 */
@Component({
	selector: 'page-user-detial-challenge',
	templateUrl: 'user-detial-challenge.html'
})
export class UserDetialChallengePage {
	userId;
	user;
	constructor(
		public navCtrl: NavController,
		public modalCtrl: ModalController,
		public api: Api,
		public urlService: UrlService,
		public navParams: NavParams,
		public noticeServe: NoticeService
	) {
		this.userId = this.navParams.get('userID');
		this.GetOtherInfo();
		this.user = {
			HeadPortrait: null,
			ID: null,
			IsEachOther: 0,
			text: null,
			Title: null,
			CityID: '',
			FSC: '0',
			GZC: '0',
			JoinDe: '0',
			Per: '0.00'
		};
	}
	/**
   * ionViewDidLoad方法是一个ionic生命周期钩。一旦一个离子视图加载它他就进行加载此函数内的代码
   */
	ionViewDidLoad() {
	
		console.log('用户详情 UserDetialChallengePage');
	}
	/**
    * 下拉刷新
    * @param even 
    */
	doRefresh(even) {
		console.log('下拉刷新');
		setTimeout(() => {
			//刷新加载
			this.ionViewDidLoad();
			even.complete();
		}, 2000);
	}

	/**
   * 消息
   */
	Btn_openChat() {
		console.log(" 消息");

	}

	/**
   * 打赏
   */
	Btn_dashang() {
		console.log(" 打赏");
		this.navCtrl.push(PageRewardPage);
	}
	/**
	 * 点赞
	 */
	dianzan() {
		//console.log(" 点赞");



	}
	jvbao_lht() {


	}

	/**
   * 初始化加载
   * @param params 
   */
	GetOtherInfo() {
		this.urlService
			.GetOtherInfo(this.userId)
			.then((data) => {
				//console.log(data);
				this.user = {
					HeadPortrait: data.Data.HeadPortrait,
					ID: data.Data.ID,
					IsEachOther: parseInt(data.Data.IsEachOther),
					text: data.Data.text,
					Title: data.Data.Title,
					CityID: data.Data.CityID,
					FSC: data.Data.FSC,
					GZC: data.Data.GZC,
					JoinDe: data.Data.JoinDe,
					Per: data.Data.Per
				};

			})
			.catch((error) => { });

		this.GetDekaronLsit(this.userId, 1);
		this.getDyList(this.userId, 1);
	}
	/**
	 * 个人信息主页
	 */
	thistankuang1() {
		//console.log("个人信息主页")
		//console.log();
		this.urlService.getUser(this.userId)
			.then(data => {
				let options = [
					{
						text: "取消拉黑",
						handler: () => {
							this.IsPullBack("1");
						}
					},
					{
						text: "拉黑",
						handler: () => {
							this.IsPullBack("2");
						}
					}
				];
				this.api.presentActionSheet("", options)
			})
	}
	/**
	 * 拉黑
	 * @param type 
	 */
	IsPullBack(type) {
	}






	tex_red = true;
	/**
   * 挑战 动态
   * @param type 1、挑战2、动态
   */
	qiehuan(type) {
		this.tex_red = !this.tex_red;
		if (this.tex_red) {
			//挑战
			this.GetDekaronLsit(this.userId, 1);
		} else {
			//动态
			this.getDyList(this.userId, 1);
		}
	}
	/**
   * 关注
   */
	Btn_addf() {
		//console.log('关注');
		this.urlService.InsertRelationshipType(this.user.IsEachOther, this.user.ID).then((data) => {
			if (this.user.IsEachOther == 0) {
				this.user.IsEachOther = 1;
			} else {
				this.user.IsEachOther = 0;
			}
		});
	}
	/**
	 * 动态列表
	 */
	DyList;
	/**
	 * 获取动态列表
	 * @param index 
	 */
	getDyList(personid, index) {

		this.urlService.GetUserDekaronDynamicList(personid, index)
			.then(data => {
				if (data.Code == 0) {
					//console.log("个人详情--获取动态列表");
					this.DyList = data.Data.Items;
				}
			})
	}

	dekarList;

	/**
	 *获取挑战列表
	 */
	GetDekaronLsit(personid, index) {
		let pageSize = 10
		this.urlService.GetUserInitiateDekaronInfo(personid, index, 0, pageSize)
			.then(data => {

				//console.log("个人详情--获取挑战列表");
				//console.log(data);
				if (data.Code == 0) {
					this.dekarList = data.Data.Items;
				}
			})
	}


}
